package com.twu.biblioteca.entity;

public class Movie extends Base {
  private final String eidr;
  private final String title;
  private final String director;
  private int year;
  private int rate;
  private boolean available = true;

  public Movie(String eidr, String title, String director) {
    this.eidr = eidr;
    this.title = title;
    this.director = director;
  }

  public int getYear() {
    return year;
  }

  public void setYear(int year) {
    this.year = year;
  }

  public int getRate() {
    return rate;
  }

  public void setRate(int rate) {
    this.rate = rate;
  }

  public String getEidr() {
    return eidr;
  }

  public String getTitle() {
    return title;
  }

  public String getDirector() {
    return director;
  }

  public boolean isAvailable() {
    return available;
  }

  public void setAvailable(boolean available) {
    this.available = available;
  }

  public Movie getMovie(Movie that) {
    Movie clonedMovie = new Movie(that.getEidr(), that.getTitle(), that.getDirector());
    clonedMovie.setAvailable(that.available);
    clonedMovie.setYear(that.year);
    clonedMovie.setRate(that.rate);
    clonedMovie.setUuid(that.getUuid());

    return clonedMovie;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof Movie)) {
      return false;
    }

    Movie movie = (Movie) o;

    if (rate != movie.rate) {
      return false;
    }
    if (year != movie.year) {
      return false;
    }
    if (director != null ? !director.equals(movie.director) : movie.director != null) {
      return false;
    }
    if (eidr != null ? !eidr.equals(movie.eidr) : movie.eidr != null) {
      return false;
    }
    if (title != null ? !title.equals(movie.title) : movie.title != null) {
      return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    int result = eidr != null ? eidr.hashCode() : 0;
    result = 31 * result + (title != null ? title.hashCode() : 0);
    result = 31 * result + (director != null ? director.hashCode() : 0);
    result = 31 * result + year;
    result = 31 * result + rate;
    return result;
  }

  @Override
  public String toString() {
    return "Movie{" +
        "title='" + title + '\'' +
        ", director='" + director + '\'' +
        ", year=" + year +
        ", rate=" + rate +
        '}';
  }
}
